/*
 * @Author: wangshuixin 2412658453@qq.com
 * @Date: 2024-06-16 15:09:01
 * @LastEditors: wangshuixin 2412658453@qq.com
 * @LastEditTime: 2024-09-05 12:51:43
 * @FilePath: /tspods/utils/hash.ts
 * @Description: 哈希值
 */
import CryptoJS from 'crypto-js'
// 用户端 >>> 生成hash值，唯一性区分
export const computeWebHash = (input: string) => {
  return CryptoJS.SHA256(input).toString();
}

// 服务端 >>> 生成hash值，唯一性区分
export const computeServerHash = async (input: string) => {
  const encoder = new TextEncoder();
  const data = encoder.encode(input);
  const hash = await crypto.subtle.digest('SHA-256', data);
  return Array.from(new Uint8Array(hash))
    .map(b => b.toString(16).padStart(2, '0'))
    .join('');
}